package com.sali.b_design_pattern.k_observer_pattern.lesson_02;

import com.sali.b_design_pattern.k_observer_pattern.lesson_02.enums.EventTypeEnum;
import com.sali.b_design_pattern.k_observer_pattern.lesson_02.listener.EmailEvenListener;
import com.sali.b_design_pattern.k_observer_pattern.lesson_02.listener.MessageEvenListener;

/**
 * @description:
 * @author: zhang hang
 * @date: 2023/3/26 14:57.
 * @version: 1.0
 */
public abstract class OrderApplicationService {

    public EventManager eventManager;

    public OrderApplicationService() {
        eventManager = new EventManager(EventTypeEnum.EMAIL, EventTypeEnum.MESSAGE);
        eventManager.subscribe(EventTypeEnum.MESSAGE, new MessageEvenListener());
        eventManager.subscribe(EventTypeEnum.EMAIL, new EmailEvenListener());

    }

    public void sendMessage(Long orderId) {
        eventManager.publisher(EventTypeEnum.MESSAGE, orderId);
        eventManager.publisher(EventTypeEnum.EMAIL, orderId);
    }

    protected abstract Long makeOrder(Long userId, Long courseId, Integer num);
}
